var express = require('express');
var mongoStore = require('connect-mongodb');
var mongoose = require('mongoose');
var util = require('util');

var auth = require('./auth');

facebook = {};
facebook.appId = '257615834280234';
facebook.appSecret = 'ec389b3c44195d6f9cfc0da469be84d7';
facebook.appDomain = 'pizeta.dyndns.org';

connection = mongoose.createConnection('mongodb://127.0.0.1/rush');
model = {};

connection.on('error', function(e) {
	util.log('Mongoose Error!');
	for(var f in e) {
		util.puts('     ' + f + ': ' + e[f]);
	}
});

connection.on('open', function() {
	require('./Models/Event');
	model.Event.startup();
	
	require('./Models/User2');
	model.User.startup();
});

app = express.createServer();
app.configure(function() {
	app.set('views', __dirname + '/Views');
	app.use(express.bodyParser());
	app.use(express.methodOverride());
	app.use(express.cookieParser());
	app.use(express.session({
		 store : new mongoStore({
			db : connection.db
		}),
		secret : '0a98dn7sf09'
	// cookie : {
	// "path" : "/",
	// "httpOnly" : true,
	// "secure" : true,
	// "maxAge" : 7200
	// }
	}));
	app.use(auth.authenticate);
	app.use(auth.facebook);
});

require('./Controls/Home');
require('./Controls/Auth');
require('./Controls/Users');
require('./Controls/Events');
require('./Controls/Comms');
require('./Controls/Checkin');

app.listen(8001);
util.log('Started Server');
